<template>
  <div class="app-container">
    <!-- v-permission="['data:lab:read']"
    v-permission="['data:lab:create']"
    v-permission="['data:lab:create']"
    v-permission="['data:lab:update']"
    v-permission="['data:lab:delete']" -->
    <!-- 查询和其他操作 -->
    <el-form :inline="true" class="demo-form-inline filter">
      <el-form-item v-if="this.$store.state.user.fsiteLevel==3" label="客户名称">
        <el-select disabled v-model="listQuery.fsiteNo" clearable filterable class="filter-item" placeholder="请选择客户名称">
          <el-option
            v-for="item in fsiteNoBelongOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
      </el-form-item>
      <el-form-item v-else label="客户名称">
        <el-select v-model="listQuery.fsiteNo" clearable filterable class="filter-item" placeholder="请选择客户名称" @change="getFpointOptions(listQuery.fsiteNo)">
          <el-option
            v-for="item in fsiteNoBelongOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="监测点">
        <el-select v-model="listQuery.fpointNo" clearable filterable class="filter-item" placeholder="请选择监测点">
          <el-option
            v-for="item in fpointOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="上级监测点">
        <el-select v-model="listQuery.fparentNo" clearable filterable class="filter-item" placeholder="请选择上级监测点">
          <el-option
            v-for="item in fpointOptions2"
            :key="item.fpointNo"
            :label="item.fpointName"
            :value="item.fpointNo"/>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button round size="medium" class="filter-item" :style="{background:buttonColor.lookup,color:buttonColor.color}" @click="handleFilter">查找</el-button>
        <el-button round size="medium" class="filter-item" :style="{background:buttonColor.add ,color:buttonColor.color}" @click="handleCreate">添加</el-button>
        <el-button round size="medium" :style="{background:buttonColor.import,color:buttonColor.color}" @click="handleUpload">导入</el-button>
      </el-form-item>
    </el-form>

    <!-- 查询结果 -->
    <el-table :height="buttonColor.clientHeight" v-loading="listLoading" :data="list" :header-cell-style="tableColor" element-loading-text="正在查询中。。。" border fit highlight-current-row>
        <el-table-column align="center" :width="buttonColor.operationTwo" label="操作" class-name="small-padding">
        <template slot-scope="scope">
           <div class="operationButton">
            <div :style="{color:buttonColor.edit,cursor:'pointer'}" @click="handleUpdate(scope.row)">
            <img src="../../../public/images/edit.png" />
            编辑
          </div>
          <div :style="{color:buttonColor.delete,cursor:'pointer'}" @click="handleDelete(scope.row)">
            <img src="../../../public/images/del.png" />
            删除
          </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column :width="buttonColor.line" :index="indexMethod" align="center" label="序" type="index"/>
      <el-table-column :formatter="formatSite" align="left" label="客户名称" prop="fsiteNo"/>
      <el-table-column align="left" label="监测点编号" prop="fpointNo"/>
      <el-table-column align="left" label="监测点名称" prop="fpointName"/>
      <el-table-column :formatter="formatfparentNo" align="left" label="上级监测点" prop="fparentNo"/>
      <el-table-column align="left" label="监测点类型" prop="fpointFlag">
        <template slot-scope="scope">
          <span style="color:#247CAA">{{ scope.row.fpointFlag | siteTypeFilter }}</span>
        </template>
      </el-table-column>
      <el-table-column align="left" :width="buttonColor.state" label="状态" prop="fpointState">
            <template slot-scope="scope">
          <span :style="{color:buttonColor.statedisable}" v-if="scope.row.fpointState===0">{{ scope.row.fpointState | statusFilter }}</span>
          <span :style="{color:buttonColor.statestart}" v-else>{{ scope.row.fpointState | statusFilter }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />

    <!-- 添加或修改对话框 -->
    <el-dialog :close-on-click-modal="false" :visible.sync="dialogFormVisible" width="auto">
      <template slot="title">
        <div :style="titleColor">{{ textMap[dialogStatus] }}</div>
      </template>
      <el-form ref="dataForm" :rules="rules" :model="dataForm" status-icon label-position="left" label-width="90px">
        <el-row>
          <el-col :span="12">
            <el-form-item class="required" v-if="this.$store.state.user.fsiteLevel==3" label="客户名称" prop="fsiteNo">
              <el-select v-model="dataForm.fsiteNo" disabled clearable filterable placeholder="请选择">
                <el-option
                  v-for="item in fsiteNoBelongOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </el-form-item>
            <el-form-item class="required" v-else label="客户名称" prop="fsiteNo">
              <el-select v-model="dataForm.fsiteNo" :disabled="dialogStatus=='update'" clearable filterable placeholder="请选择" @change="getStations(dataForm.fsiteNo, true)">
                <el-option
                  v-for="item in fsiteNoBelongOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item class="el-form-item-small required" label="监测点类型" prop="fpointFlag">
              <el-select v-model="dataForm.fpointFlag" :disabled="dialogStatus=='update'" class="filter-item" placeholder="请选择监测点类型">
                <el-option v-for="(key, value) in siteTypeMap" :key="key" :label="key" :value="value"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item class="required" label="监测点编号" prop="fpointNo">
              <el-input v-model="dataForm.fpointNo" :disabled="dialogStatus==='update'" type="number"/><!-- oninput="value=value.replace(/[^\d]/g,'')"-->
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item class="required" label="监测点名称" prop="fpointName">
              <el-input v-model="dataForm.fpointName"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
            <el-col :span="12">
            <el-form-item class="required" label="负责人" prop="fperson">
              <div style="display:flex;justify-content:flex-start;align-items:center">
            <el-select style="display: inline-block" clearable filterable v-model="dataForm.fperson" class="filter-item" placeholder="请选择负责人">
                  <el-option
                  v-for="item in getListfperson"
                :key="item.value"
                :label="item.label"
                :value="item.value"/>
                </el-select>
            <i class="el-icon-search selectI" @click="searchDialoguse('add')"/>
          </div>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item class="el-form-item-small required" label="状态" prop="fpointState">
              <el-select v-model="dataForm.fpointState" class="filter-item" placeholder="请选择状态">
                <el-option v-for="(key, value) in statusMap" :key="key" :label="key" :value="value"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
          <el-row>
           <el-col :span="12">
            <el-form-item class="required" label="上级监测点" prop="fparentNo">
              <el-select @change="fparentNoChange()" v-model="dataForm.fparentNo" :disabled="dataForm.fpointFlag!=='0'" clearable class="filter-item" placeholder="请选择上级监测点">
                <el-option
                  v-for="item in eqtActionOptions"
                  :key="item.fpointNo"
                  :label="item.fpointName"
                  :value="item.fpointNo"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item class="required" label="楼层" prop="flayerName">
              <div style="display:flex;justify-content:flex-start;align-items:center">
            <el-input v-model="dataForm.flayerName" />
            <i class="el-icon-search selectI" @click="searchDialoglayer"/>
          </div>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="纬度" prop="fpointL">
              <el-input v-model="dataForm.fpointL"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="经度" prop="fpointD">
              <el-input v-model="dataForm.fpointD"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="高度" prop="fpointH">
              <el-input v-model="dataForm.fpointH" @focus="pop3(dataForm.fsiteNo,dataForm.fparentNo)"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="宽度" prop="fpointW">
              <el-input v-model="dataForm.fpointW" @focus="pop3(dataForm.fsiteNo,dataForm.fparentNo)"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-show="dataForm.fpointFlag==2">
          <el-col :span="12">
            <el-form-item label="监测点图片(2M内)" prop="fimage">
              <!--<el-input v-model="dataForm.fimage"/>-->
              <el-upload
                v-model="dataForm.fimage"
                :show-file-list="false"
                :on-success="handleAvatarSuccess"
                :before-upload="beforeAvatarUpload"
                :action="uploadPath"
                :data="formdata2(dataForm.fpointNo)"
                class="avatar-uploader">
                <img v-if="dataForm.fimage" :src="dataForm.fimage" class="avatar">
                <i v-else class="el-icon-plus avatar-uploader-icon"/>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item class="text" style="width:99%" label="视频URL" prop="fvideoUrl">
              <el-input v-model="dataForm.fvideoUrl" />
            </el-form-item>
          </el-col>
        </el-row>
        <!--<el-form-item label="操作员" prop="foperator">
          <el-input v-model="dataForm.foperator"/>
        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button round :style="{background:buttonColor.cancel,color:buttonColor.colorone}" @click="dialogFormVisible = false">取消</el-button>
        <el-button round v-if="dialogStatus=='create'" :style="{background:buttonColor.confirm,color:buttonColor.color}" @click="createData">确定</el-button>
        <el-button round v-else :style="{background:buttonColor.confirm,color:buttonColor.color}" @click="updateData">确定</el-button>
      </div>
    </el-dialog>

        <!-- 导出弹窗 -->
    <el-dialog width="auto" :close-on-click-modal="false" :visible.sync="uploadVisible">
       <template slot="title">
      <div :style="exportColor">教室</div>
    </template>
      <div style="width:300px;height:200px;display: flex;flex-direction: column;align-items: center">
          <el-upload
          :on-success="uploadFileSuccess"
          :headers="headers"
          :action="uploadPath2"
          :data="{'tableName':'import_i_ts_point'}"
          :show-file-list="false"
          class="filter-item"
          style="margin-top:20px"
          accept=".xlsx">
          <el-button round size="medium" icon="el-icon-upload" :style="{background:buttonColor.import,color:buttonColor.color}">导入</el-button>
        </el-upload>
        <div style="margin-top:30px;text-decoration:underline">
          <a :href="downUrl" style="color: blue">模板文件下载</a>
        </div>

      </div>
    </el-dialog>

    <!-- 百度地图 -->
    <el-dialog :close-on-click-modal="false" :visible.sync="dialogFormVisible2" fullscreen width="1200px" height="800px" style="width: 100%; height: 600px; padding-top:0px;">
      <template slot="title">
        <div :style="titleColor">百度地图</div>
      </template>
      <div slot="title" align="right" style="margin-top:-10px; margin-right: 30px">
        <el-button :style="{background:buttonColor.cancel,color:buttonColor.colorone}" @click="dialogFormVisible2 = false">取消</el-button>
        <el-button :style="{background:buttonColor.confirm,color:buttonColor.color}" @click="setLatLng">确定</el-button>
      </div>
      <cmap style="margin-top:-30px; width: 100%;" @transfer="getPoint"/><!-- :center="dataForm.fsiteParent" :keyword="dataForm.fpointName"-->
    </el-dialog>

    <!-- 图片定位 -->
    <el-dialog :close-on-click-modal="false" :visible.sync="dialogFormVisible3">
      <!--<div id="image" style="position: relative">
        <img style="height: 100%; width: 100%" class="map-img" src="//www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png" @click="getClickInfo">
        <span id="span" class="el-icon-location" style="position: absolute; left: 0px; top: 0px; color: rgb(30,144,255); fontSize: 25px"/>
      </div>-->
      <div id="image" style="position: relative">
        <img :src="imgUrl" style="height: 100%; width: 100%" class="map-img" @click="getClickInfo">
        <span id="span" class="el-icon-location" style="position: absolute; left: 0px; top: 0px; color: rgb(30,144,255); fontSize: 40px"/>
        <el-button :style="{background:buttonColor.cancel,color:buttonColor.colorone}" @click="dialogFormVisible3 = false">取消</el-button>
        <el-button :style="{background:buttonColor.confirm,color:buttonColor.color}" @click="setPosition">确定</el-button>
      </div>
    </el-dialog>
     <!-- 搜索弹出框 -->
    <userDialog :searchVisibleuse.sync="searchVisibleuse"  :fsiteNo.sync="userDialogFsiteNo" :tableColor="tableColor" @userDialog="userDialogValue" />
     <layerDialog :layerVisible.sync="layerVisible" :fparentNo.sync="layerDialogfparentNo" :fsiteNo.sync="layerDialogFsiteNo" :tableColor="tableColor" @layerDialog="layerDialogValue" />
  </div>
</template>

<script>
import $ from 'jquery'
import { listRoom, createRoom, updateRoom, deleteRoom } from '@/api/room'
import { uploadPath2 } from "@/api/area";
import { getToken } from '@/utils/auth'
import { getApiUrl } from '@/utils/request'
import { fsiteOptionsByLevel, fpointOptions, fpointOptions2, getListArea } from '@/api/area'
import Pagination from '@/components/Pagination'
import moment from 'moment'
import { uploadPath } from '@/api/eqtOrder'
import cmap from './baiduMap'
import { listPointByFsiteNo2 } from '@/api/airAlarm'
import { tableColor, titleColor,buttonColor,exportColor } from '@/filters/index'
import { listtsLayer} from '@/api/tsLayer'
import LayerDialog from '@/components/LayerDialog'
import UserDialog from '@/components/UserDialog'

const siteTypeMap = {
  0: '室内'
}

const statusMap = {
  0: '禁用',
  1: '启用'
}

export default {
  name: 'Lab',
  components: { Pagination, cmap, LayerDialog, UserDialog },
  filters: {
    siteTypeFilter(type) {
      return siteTypeMap[type]
    },
    statusFilter(type) {
      return statusMap[type]
    }
  },
  data() {
    return {
      uploadVisible: false,
      downUrl: null,
      exportColor,
      getListfperson:[],
      layerListAll:[],
      searchVisibleuse: false,
      userDialogFsiteNo: null,
      userFlag:null,
      layerVisible:false,
      layerDialogFsiteNo:null,
      layerDialogfparentNo:null,
      uploadPath,
      uploadPath2,
      list: null,
      total: 0,
      parentnoAll: [],
      fsiteNoBelongOptions: [],
      fpointOptions: null,
      fpointOptions2: null,
      imgUrl: null,
      center: '北京',
      lat: 0,
      lng: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        fsiteNo: undefined,
        fpointNo: undefined,
        fimage: undefined,
        fparentNo: undefined,
        fpointFlag: undefined,
        fpointState: 2,
        sort: 'create_time',
        order: 'desc'
      },
      siteTypeMap,
      statusMap,
      dataForm: {
        id: undefined,
        fpointNo: undefined,
        fimage: undefined,
        fpointName: undefined,
        fsiteNo: undefined,
        fparentNo: undefined,
        fpointFlag: undefined,
        fpointL: undefined,
        fpointD: undefined,
        fpointH: undefined,
        fpointW: undefined,
        fvideoUrl: undefined,
        fpointState: undefined,
        fupddate: undefined,
        foperator: undefined,
        fperson: undefined,
        flayerNo: undefined,
        flayerName: undefined,
      },
      eqtActionOptions: [],
      dialogFormVisible: false,
      dialogFormVisible2: false,
      dialogFormVisible3: false,
      dialogStatus: '',
      textMap: {
        update: '编辑',
        create: '创建'
      },
      tableColor: tableColor,
      titleColor: titleColor,
      buttonColor:buttonColor,
      rules: {
        fpointNo: [
          { required: true, message: '监测点编号不能为空', trigger: 'blur' }
        ],
        fpointName: [
          { required: true, message: '监测点名称不能为空', trigger: 'blur' }
        ],
        fsiteNo: [
          { required: true, message: '客户名称不能为空', trigger: 'blur' }
        ],
        fparentNo: [
          { required: true, message: '上级监测点编号不能为空', trigger: 'blur' }
        ],
        flayerName: [
          { required: true, message: '楼层不能为空', trigger: 'blur' }
        ],
        fpointFlag: [
          { required: true, message: '监测点类型不能为空', trigger: 'blur' }
        ],
        fperson: [
          { required: true, message: '负责人不能为空', trigger: 'blur' }
        ],
        fpointState: [
          { required: true, message: '状态不能为空', trigger: 'blur' }
        ]
      },
      permissionDialogFormVisible: false,
      systemPermissions: null,
      assignedPermissions: null,
      permissionForm: {
        roleId: undefined,
        permIds: []
      },
    }
  },
  computed: {
    headers() {
      return {
        'Authorization': getToken()
      }
    }
  },
  created() {
      this.downUrl = getApiUrl() + 'xlsx/1-8实验室.xlsx'
      if(this.$store.state.user.fsiteLevel==3){
      this.listQuery.fsiteNo=this.$store.state.user.fsiteNo
       getListArea({flag:10,arg1:this.$store.state.user.fsiteNo})
          .then(response => {
            this.fpointOptions = response.data.data.list
          })
          .catch(() => {
            this.fpointOptions = []
          })
        listPointByFsiteNo2(this.$store.state.user.fsiteNo)
          .then(response => {
            this.fpointOptions2 = response.data.data.list
          })
          .catch(() => {
            this.fpointOptions2 = []
          })
          getListArea({flag:13,arg1:this.$store.state.user.fsiteNo})
          .then(response => {
            this.getListfperson = response.data.data.list
          })
          .catch(() => {
            this.getListfperson = []
          })
    }

    this.getList()
    fsiteOptionsByLevel(3)
      .then(response => {
        this.fsiteNoBelongOptions = response.data.data.list
      })
      .catch(() => {
        this.fsiteNoBelongOptions = []
      })

       listPointByFsiteNo2()
          .then(response => {
            this.parentnoAll = response.data.data.list
          })
          .catch(() => {
            this.parentnoAll = []
          })

  },
  methods: {
    // 上级监测点
    fparentNoChange(){
      this.dataForm.flayerNo = ''
      this.dataForm.flayerName = ''
    },

     // 搜索人员弹出框
    searchDialoguse(value) {
      this.userFlag = value
      if(value === 'add'){
        this.userDialogFsiteNo = this.dataForm.fsiteNo
      }else{
        this.userDialogFsiteNo = this.listQuery.fsiteNo
      }
      this.searchVisibleuse = true
    },

    // 人员弹出框返回值
    userDialogValue(value){
      if(this.userFlag==='add'){
        console.log(value.user)
        this.dataForm.fperson = value.user.id.toString()
      }else{
        this.listQuery.fperson = value.user.id
      }
    },

      // 楼层弹出框
    searchDialoglayer(value) {
      this.layerDialogFsiteNo = this.dataForm.fsiteNo
      if(this.dataForm.fparentNo){
        this.layerDialogfparentNo = this.dataForm.fparentNo
      }else{
          this.$notify.info({
          message: '请先选择上级监测点'
        })
        return
      }
      this.layerVisible = true
    },

    // 楼层弹出框返回值
    layerDialogValue(value){
      this.dataForm.flayerName = value.data.flayerName
      this.dataForm.flayerNo = value.data.flayerNo
    },

    /** *
     * 图片点击事件。
     */
    getClickInfo(e) {
      document.getElementById('span').style.setProperty('left', (e.offsetX - 20).toString() + 'px')
      document.getElementById('span').style.setProperty('top', (e.offsetY - 25).toString() + 'px')
    },
    setPosition() {
      this.dialogFormVisible3 = false
      var a = document.getElementById('image')
      this.dataForm.fpointH = a.clientHeight
      this.dataForm.fpointW = a.clientWidth
      this.dataForm.fpointD = document.getElementById('span').style.getPropertyValue('left').replace('px', '')
      this.dataForm.fpointL = document.getElementById('span').style.getPropertyValue('top').replace('px', '')
      this.$refs['dataForm'].validateField('fpointL')
      this.$refs['dataForm'].validateField('fpointD')
      this.$refs['dataForm'].validateField('fpointH')
      this.$refs['dataForm'].validateField('fpointW')
    },
    pop3(fsiteNo, fparentNo) {
      if ((fparentNo === undefined || fparentNo === null || fparentNo === '' || fparentNo === '0') && (fsiteNo === undefined || fsiteNo === null || fsiteNo === '')) {
        this.$notify.info({
          message: '请先选择 客户名称 或 上级监测点'
        })
        return
      }
      if (fparentNo === undefined || fparentNo === null || fparentNo === '' || fparentNo === '0') { // 教学楼
        // this.imgUrl = 'air/images/002/site/' + fsiteNo + '.png'
        this.imgUrl = '300003.png'
      } else { // 教室
        this.imgUrl = 'air/images/002/indoor/' + fparentNo + '.png'
      }
      var that = this
      $.ajax({
        type: 'get',
        // url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png',
        // url: this.imgUrl,
        url: '300003.png',
        success: function(data) {
          that.dialogFormVisible3 = true
        },
        error: function(data) {
          return
        }
      })
    },
    // 导入
     uploadFileSuccess: function(response) {
       this.uploadVisible = false
      this.$notify.success({
        title: '导入',
        dangerouslyUseHTMLString:true,
        message: response.data
      })
    },
    handleUpload(){
      this.uploadVisible = true
    },
    formdata2: function(fpointno) {
      // const formdata = new FormData()
      // formdata.append('fpointno', '123456')
      return { 'ftype': '1', 'fpointno': fpointno }
    },
    handleAvatarSuccess(res, file) {
      // this.dataForm.fimage = URL.createObjectURL(file.raw)
      this.dataForm.fimage = res.data
      const time = new Date().getTime()
      this.dataForm.fimage = `${this.dataForm.fimage}?time=${time}`
    },
    beforeAvatarUpload(file) {
      // const isJPG = file.type === 'image/jpeg'
      const isLt2M = file.size / 1024 / 1024 < 2

      // if (!isJPG) {
      //   this.$message.error('上传头像图片只能是 JPG 格式!')
      // }
      if (!isLt2M) {
        this.$message.error('上传图片大小不能超过 2MB!')
      }
      return isLt2M // isJPG &&
    },
    formatStatus: function(row, column) {
      return row.fpointState === 1 ? '启用' : '禁用'
    },
    dateFormat(row, column) {
      const date = row[column.property]
      if (date === undefined) {
        return ''
      }
      return moment(date).format('YYYY-MM-DD HH:mm:ss')
    },
    formatSite: function(row, column) {
      if (this.fsiteNoBelongOptions.length > 0) {
        for (let i = 0; i < this.fsiteNoBelongOptions.length; i++) {
          if (row.fsiteNo === this.fsiteNoBelongOptions[i].value) {
            return this.fsiteNoBelongOptions[i].label
          }
        }
        return ''
      } else {
        return ''
      }
    },
    formatfparentNo(row){
       if (this.parentnoAll.length > 0) {
        for (let i = 0; i < this.parentnoAll.length; i++) {
          if (row.fparentNo == this.parentnoAll[i].fpointNo) {
            return this.parentnoAll[i].fpointName
          }
        }
        return ''
      } else {
        return ''
      }
    },
    getFpointOptions(fsiteNo) {
      this.listQuery.fpointNo = undefined
      this.listQuery.fparentNo = undefined
      this.fpointOptions = []
      this.fpointOptions2 = []
      if (fsiteNo) {
        getListArea({flag:10,arg1:fsiteNo})
          .then(response => {
            this.fpointOptions = response.data.data.list
          })
          .catch(() => {
            this.fpointOptions = []
          })
        listPointByFsiteNo2(fsiteNo)
          .then(response => {
            this.fpointOptions2 = response.data.data.list
          })
          .catch(() => {
            this.fpointOptions2 = []
          })
      }
    },
    getStations(fsiteNo, clearFparentNo) {
      this.eqtActionOptions = []
      if (clearFparentNo) {
        this.dataForm.fparentNo = ''
        this.dataForm.flayerNo = ''
        this.dataForm.flayerName = ''
      }
      if (fsiteNo) {
        listPointByFsiteNo2(fsiteNo)
          .then(response => {
            this.eqtActionOptions = response.data.data.list
          })
          .catch(() => {
            this.eqtActionOptions = []
          })
          getListArea({flag:13,arg1:fsiteNo})
          .then(response => {
            this.getListfperson = response.data.data.list
          })
          .catch(() => {
            this.getListfperson = []
          })
      }
    },
    getList() {
      this.listLoading = true
      this.listQuery.fpointFlag = 0
      listRoom(this.listQuery)
        .then(response => {
          this.list = response.data.data.list
          this.total = response.data.data.total
          this.listLoading = false
        })
        .catch(() => {
          this.list = []
          this.total = 0
          this.listLoading = false
        })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    resetForm() {
      this.dataForm = {
        id: undefined,
        fpointNo: undefined,
        fimage: undefined,
        fpointName: undefined,
        fsiteNo: undefined,
        fparentNo: undefined,
        fpointFlag: undefined,
        fpointL: undefined,
        fpointD: undefined,
        fpointH: undefined,
        fpointW: undefined,
        fvideoUrl: undefined,
        fpointState: undefined,
        fupddate: undefined,
        foperator: undefined,
        fperson: undefined,
        flayerNo: undefined,
        flayerName: undefined,
      }
    },
    handleCreate() {
      this.resetForm()
      this.dialogStatus = 'create'
      this.dialogFormVisible = true
      this.dataForm.fpointState = '1'
      this.dataForm.fpointFlag = '0'
      this.eqtActionOptions = []
      if(this.$store.state.user.fsiteLevel==3){
        this.dataForm.fsiteNo = this.$store.state.user.fsiteNo
        listPointByFsiteNo2(this.$store.state.user.fsiteNo)
          .then(response => {
            this.eqtActionOptions = response.data.data.list
          })
          .catch(() => {
            this.eqtActionOptions = []
          })
      }
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    },
    clickMap() {
      // this.resetForm()
      this.dialogFormVisible2 = true
      this.lat = 0
      this.lng = 0
      // this.dataForm.fsiteState = '1'
      // this.$nextTick(() => {
      //   this.$refs['dataForm'].clearValidate()
      // })
    },
    getPoint(point) {
      this.lat = point.lat
      this.lng = point.lng
    },
    setLatLng() {
      this.dialogFormVisible2 = false
      this.dataForm.fpointL = this.lat
      this.dataForm.fpointD = this.lng
      this.$refs['dataForm'].validateField('fpointL')
      this.$refs['dataForm'].validateField('fpointD')
    },
    // 楼层名称
       formatflayerName(row){
       if (this.layerListAll.length > 0) {
        for (let i = 0; i < this.layerListAll.length; i++) {
          if (row.flayerNo == this.layerListAll[i].flayerNo) {
            return this.layerListAll[i].flayerName
          }
        }
      } else {
        return ''
      }
    },
    createData() {
      this.$refs['dataForm'].validate(valid => {
        if (valid) {
          this.dataForm.foperator = this.$store.state.user.id
          this.dataForm.fupddate = new Date()
          createRoom(this.dataForm)
            .then(response => {
              this.list.unshift(response.data.data)
              this.dialogFormVisible = false
              this.$notify.success({
                title: '成功',
                message: '添加教室资料成功'
              })
            })
            .catch(response => {
              this.$notify.error({
                title: '失败',
                message: response.data.data
              })
            })
        }
      })
    },
    handleUpdate(row) {
      this.dataForm = Object.assign({}, row)
      this.dataForm.fpointFlag = row.fpointFlag.toString()
      this.dataForm.fpointState = row.fpointState.toString()
      this.getStations(row.fsiteNo, false)

      listtsLayer({limit:-1,fsiteNo:row.fsiteNo,fpointNo:row.fparentNo})
      .then(response => {
        this.layerListAll = response.data.data.list
          for (let i = 0; i < this.layerListAll.length; i++) {
          if (row.flayerNo == this.layerListAll[i].flayerNo) {
            this.dataForm.flayerName = this.layerListAll[i].flayerName
          }
        }
        this.dialogStatus = 'update'
           this.dialogFormVisible = true
           this.$nextTick(() => {
           this.$refs['dataForm'].clearValidate()
        })
      })
      .catch(() => {
        this.layerListAll = []
      })


    },
    updateData() {
      this.$refs['dataForm'].validate(valid => {
        if (valid) {
          this.dataForm.foperator = this.$store.state.user.id
          this.dataForm.fupddate = new Date()
          updateRoom(this.dataForm, this.$route.query.id)
            .then(() => {
              for (const v of this.list) {
                if (v.fpointNo === this.dataForm.fpointNo) {
                  const index = this.list.indexOf(v)
                  this.dataForm.fpointState = parseInt(this.dataForm.fpointState)
                  this.list.splice(index, 1, this.dataForm)
                  break
                }
              }
              this.dialogFormVisible = false
              this.$notify.success({
                title: '成功',
                message: '更新管理员成功'
              })
            })
            .catch(response => {
              this.$notify.error({
                title: '失败',
                message: response.data.data
              })
            })
        }
      })
    },
    handleDelete(row) {
      this.$confirm('是否要删除该监测点资料', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteRoom(row)
          .then(response => {
            this.$notify.success({
              title: '成功',
              message: '删除监测点资料成功'
            })
            const index = this.list.indexOf(row)
            this.list.splice(index, 1)
          })
          .catch(response => {
            this.$notify.error({
              title: '失败',
              message: response.data.data
            })
          })
      })
    },
    indexMethod(index) {
      index = index + 1
      return index
    }
  }
}
</script>

<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
     /*处理input type = number的上下箭头*/
   input::-webkit-outer-spin-button,
   input::-webkit-inner-spin-button {
     -webkit-appearance: none;
   }
  input[type="number"]{
    -moz-appearance: textfield;
  }
</style>
